package leetcode;


/**
 * 长度最小的子数组
 */
public class LeetCode209 {
    public int minSubArrayLen(int s, int[] nums) {
        int left = 0, sum = 0, max = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            while (sum >= s) {
                max = Math.min(i - left, max);
                sum -= nums[left++];
            }
        }
        return max == Integer.MAX_VALUE ? 0 : max + 1;
    }

    public static void main(String[] args) {
        LeetCode209 leetCode209 = new LeetCode209();
        System.out.println(leetCode209.minSubArrayLen(7, new int[]{2, 3, 1, 2, 4, 3}));
    }
}